/**
 * 
 */
package scriptrunner.execution;

import java.io.Serializable;

/**
 * @author Administrator
 * 
 */
public class IfStatement extends Statement implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4451688685572161033L;

	public IfStatement(CompareExpr ce, StatementList slThen) {
		this.ce = ce;
		this.slThen = slThen;
		this.slElse = null;
	}

	public IfStatement(CompareExpr ce, StatementList slThen,
			StatementList slElse) {
		this.ce = ce;
		this.slThen = slThen;
		this.slElse = slElse;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * scriptrunner.execution.Statement#Execute(scriptrunner.execution.Session)
	 */
	@Override
	public boolean Execute(Session se) throws ExecuteErrorException {
		if (ce.CalculateResult(se)) {
			return slThen.Execute(se);
		} else {
			if (slElse != null) {
				return slElse.Execute(se);
			} else {
				return false;
			}
		}
	}

	CompareExpr ce;
	StatementList slThen, slElse;
}
